using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace LDBUtilities
{
    public partial class TransparentLabel : Control
    {
        private bool bPaintOnce = false;

        public TransparentLabel()
        {
            InitializeComponent();
        }

        private StringAlignment textAlign = StringAlignment.Near;
        public StringAlignment TextAlign
        {
            get
            {
                return textAlign;
            }
            set
            {
                textAlign = value;
            }
        }


        protected override void OnPaintBackground(PaintEventArgs e)
        {
            //base.OnPaintBackground(e);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            if (!bPaintOnce)
            {
                bPaintOnce = true;

                this.Visible = false;
                this.Parent.Invalidate(this.Bounds);
                this.Parent.Update();
                this.Visible = true;
                return;
            }
            else
            {
                bPaintOnce = false;

                Graphics g = e.Graphics;
                Font font = this.Font;
                SolidBrush brush = new SolidBrush(this.ForeColor);

                // Set format of string.
                StringFormat drawFormat = new StringFormat();
                drawFormat.Alignment = textAlign;

                RectangleF layoutRectangle = new RectangleF(0, 0, Width, Height);

                g.DrawString(this.Text, font, brush, layoutRectangle, drawFormat);
                g.Dispose();
            }
            base.OnPaint(e);
        }

        public override string Text
        {
            get
            {
                return base.Text;
            }
            set
            {
                Invalidate();
                base.Text = value;
            }
        }
/*
        private void InitializeComponent()
        {
            base.InitializeComponent();
            base.SuspendLayout();
            base.Size = new Size(100, 25);
            base.ResumeLayout(false);
        }
        */
   }
 
}
